package org.hisp.dhis.wsclient.j2me.javarosa;

import java.io.*;
import org.xml.sax.*;
import javax.xml.parsers.*;
import org.xml.sax.helpers.*;
import javax.microedition.midlet.*;
import javax.microedition.io.*;
//import javax.microedition.io.file.*;
import javax.microedition.lcdui.*;

public class RESTClient{

  public RESTClient(){
  super();
  this.retrieveAndParse();
  }
	
	String msg;
	
	public void run(){
	this.retrieveAndParse();
	}
	
	protected void retrieveAndParse()
	{
  
  
	try
      {
      SAXParserFactory factory = SAXParserFactory.newInstance();
      SAXParser saxParser = factory.newSAXParser();

	// Initialize the URI and get XML Document InputStream
	String uri = "http://localhost:8080/dhis-web-webservice/getAllDataSets.service";
    HttpConnection hc = (HttpConnection)Connector.open(uri);
	InputStream inputStream = hc.openInputStream();
	// Create an InputSource from the InputStream
	InputSource inputSource = new InputSource(inputStream);
	hc.close();
	// Parse the input XML document stream, using my event handler
	saxParser.parse(inputSource, new MyEventHandler(this));
		}
    catch(Exception ex) {
	System.out.println("Problem parsing...please check your connection");
	msg = "Please check your webservice connection";
	}
	

	
	}

  public void setResult(String msgsent)
  {
    msg = msgsent;
  }

  public String getResult()
  {
    return msg;
  }
  
}
